package idiet.dao.hibernate;

import idiet.bean.Nation;

import java.util.List;

import org.hibernate.annotations.Parent;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository("nationDao")
public class NationDao extends BaseDao {
	public Nation getNationById(int nationId){
		return (Nation) this.sessionFactory
				.getCurrentSession()
				.createCriteria(Nation.class)
				.add(Restrictions.eq("id", nationId))
				.uniqueResult();
	}
	@SuppressWarnings("unchecked")
	public List<Nation> getNationsByNationName(String name){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(Nation.class)
				.add(Restrictions.like("name",name))
				.list();
	}
	@SuppressWarnings("unchecked")
	public List<Nation> getNations(){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(Nation.class)
				.list();
	}
	public void createNation(Nation nation){
		this.sessionFactory
		.getCurrentSession()
		.save(nation);
	}
	public void updateNation(Nation nation){
		this.sessionFactory
		.getCurrentSession()
		.update(nation);
	}
	public void deleteNation(Nation nation){
		this.sessionFactory
		.getCurrentSession()
		.delete(nation);
	}
}
